Skip to content

fix: handle bare numeric and negative durations in Wait action handler#412

Open
nankingjing wants to merge 2 commits into
zai-org:mainfrom
nankingjing:fix-wait-action-duration
Open

fix: handle bare numeric and negative durations in Wait action handler#412
nankingjing wants to merge 2 commits into
zai-org:mainfrom
nankingjing:fix-wait-action-duration

Conversation

@nankingjing

Copy link
Copy Markdown

Summary

Fixes a bug in ActionHandler._handle_wait where the Wait action silently failed when the model returned a bare numeric duration (int/float) instead of a string like "3 seconds".

Root cause

_handle_wait always calls .replace("seconds", "") on action.get("duration"). When a model emits do(action="Wait", duration=3), ast.literal_eval returns the integer 3. Calling .replace() on an int raises AttributeError, which the except ValueError clause does not catch, so the action falls through to execute()'s generic handler and reports success=False with Action failed: 'int' object has no attribute 'replace' — no actual wait happens. A negative duration string (e.g. "-5 seconds") is a second latent defect: it parses to -5.0 and time.sleep(-5.0) raises ValueError.

Fix (phone_agent/actions/handler.py)

  • Check isinstance(duration_raw, (int, float)) before calling string methods; convert numeric input to float directly.
  • Broaden the exception clause to except (ValueError, TypeError).
  • Clamp negative durations to 1.0 so time.sleep cannot raise.

The documented happy path duration="N seconds" is unchanged.

Test (tests/test_wait_action.py)

Seven deterministic tests driving ActionHandler.execute, covering: string with unit, string without unit, missing key (default), bare int (the bug), bare float, unparseable fallback, and negative clamp. time.sleep is patched — no device or network access.

Verification

Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant